//
//  BaseModel.m
//  Cartoon
//
//  Created by dllo on 15/10/28.
//  Copyright © 2015年 YSZ. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

// 1.KVC的纠错方法
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{

}

- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}

// 2.遍历构造器方法

+ (instancetype)modelWithDic:(NSDictionary *)dic
{
// 1. self 谁调用这个方法,self就是谁
    // 2. 多态: 父类的指针可以指向子类的对象
    BaseModel *base = [[self alloc] init];
    [base setValuesForKeysWithDictionary:dic];
    return base;
}

// 3. 只针对model的外部操作也可以放到基类中
+ (NSMutableArray *)modelsWithArr:(NSArray *)dicArr
{
    NSMutableArray *sourceArr = [NSMutableArray array];
    for (NSDictionary *dic in dicArr) {
        
        BaseModel *base = [self modelWithDic:dic];
        [sourceArr addObject:base];
    }
    return sourceArr;
    
}


@end
